package com.iwe3.protal.service;

import com.iwe3.protal.common.ShoppingGoodsInfo;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;

import java.util.concurrent.TimeUnit;

public class OrderServiceImpl implements IOrderService {
    private final RedissonClient redissonClient;

    public OrderServiceImpl(RedissonClient redissonClient) {
        this.redissonClient = redissonClient;
    }

    @Override
    public void makeOrder(ShoppingGoodsInfo goodsInfo, Integer addressId, Long userId) {
        RLock lock = redissonClient.getLock("order:makeOrder:"+userId);
        try {
            lock.lock();
            TimeUnit.SECONDS.sleep(50);
        }
        catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        finally {
            lock.unlock();
        }

    }
}
